package com.xbkj.pgrp.server.model.common;

import lombok.Getter;
import lombok.Setter;
import xyz.erupt.annotation.Erupt;
import xyz.erupt.annotation.EruptField;
import xyz.erupt.annotation.sub_erupt.Power;
import xyz.erupt.annotation.sub_erupt.Tree;
import xyz.erupt.annotation.sub_field.Edit;
import xyz.erupt.annotation.sub_field.EditType;
import xyz.erupt.annotation.sub_field.View;
import xyz.erupt.annotation.sub_field.sub_edit.ReferenceTreeType;
import xyz.erupt.jpa.model.BaseModel;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


@Entity
@Erupt(
        name = "地区编码",
        tree = @Tree(pid = "parentModel.id", label = "name", expandLevel=1),
        orderBy = "AreaDictModel.name asc",
        power = @Power(export = false, importable = false, add = false, edit = false,delete = false)
)
@Table(name = "efs_area_dict")
@Getter
@Setter
public class AreaDictModel extends BaseModel {
    @EruptField(
            views = @xyz.erupt.annotation.sub_field.View(title = "地区编码"),
            edit = @xyz.erupt.annotation.sub_field.Edit(title = "地区编码")
    )
    private String code;
    @EruptField(
            views = @xyz.erupt.annotation.sub_field.View(title = "地区名称"),
            edit = @xyz.erupt.annotation.sub_field.Edit(title = "地区名称")
    )
    private String name;

    @EruptField(views = @View(title = "层级"), edit = @Edit(title = "层级", notNull = true, type = EditType.NUMBER))
    private Integer levels;


    @ManyToOne
    @EruptField(
            edit = @Edit(
                    title = "上级地区",
                    type = EditType.REFERENCE_TREE,
                    referenceTreeType = @ReferenceTreeType(pid = "parentModel.id")
            )
    )
    private AreaDictModel parentModel;
}
